package com.wnxy.pawnbackgroundsystem.controller;


import com.wnxy.pawnbackgroundsystem.commons.OssTemplate;
import com.wnxy.pawnbackgroundsystem.dto.GetBigSortsDto;
import com.wnxy.pawnbackgroundsystem.dto.SortPageDto;
import com.wnxy.pawnbackgroundsystem.dto.userDto.GoodsSmallSortDto;
import com.wnxy.pawnbackgroundsystem.param.*;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.impl.SortServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 商品分类表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-14
 */
@RestController
@RequestMapping("/pawnbackgroundsystem/sort")
@Slf4j
public class SortController {

    @Autowired
    private SortServiceImpl sortServiceImpl;
    //分页带条件查询大类
    @PostMapping("/getBigSort")
    @CrossOrigin("*")
    public Result getBigSort(@RequestBody GetBigSortParam getBigSortParam){
        log.info("分页带条件查询参数接口 参数={}",getBigSortParam);
        SortPageDto bigSort = sortServiceImpl.getBigSort(getBigSortParam);
        return new Result(true,"2002","查询集合成功",bigSort);
    }
    //查询大类返回主键和大类名称
    @GetMapping("/getBigSorts")
    @CrossOrigin("*")
    public Result getBigSorts(){
        log.info("查询大类返回格式化主键和名称接口");
        List<GetBigSortsDto> bigSorts = sortServiceImpl.getBigSorts();
        return new Result(true,"2002","查询集合成功",bigSorts);
    }
    //修改大类
    @PutMapping("/updateBigSort")
    @CrossOrigin("*")
    public Result updateBigSort(@RequestBody UpdateBigSortParam updateBigSortParam){
        log.info("修改大类接口 参数={}",updateBigSortParam);
        sortServiceImpl.updateBigSort(updateBigSortParam);
        return new Result(true,"2002","修改成功",null);
    }
    //删除多个大类
    @DeleteMapping("/delBigSort")
    @CrossOrigin("*")
    public Result delBigSort(@RequestParam(value = "intList") List<Integer> intList){
        log.info("删除多个大类接口 参数={}",intList);
        sortServiceImpl.delBigSort(intList);
        return new Result(true,"2002","删除成功",null);
    }
    //新增大类
    @CrossOrigin("*")
    @PostMapping("/addBigSort")
    public Result addBigSort(@RequestBody AddBigSortParam addBigSortParam){
        log.info("新增大类接口 参数={}",addBigSortParam);
        sortServiceImpl.addBigSort(addBigSortParam);
        return new Result(true,"2002","新增成功",null);
    }
    //分页带条件查询小类
    @PostMapping("/getSmallSort")
    @CrossOrigin("*")
    public Result getSmallSort(@RequestBody GetSmallSortParam getSmallSortParam){
        log.info("分页带条件查询小类接口 参数={}",getSmallSortParam);
        SortPageDto smallSort = sortServiceImpl.getSmallSort(getSmallSortParam);
        return new Result(true,"2002","查询集合成功",smallSort);
    }
//    新增小类
//    @CrossOrigin("*")
//    @PostMapping("/addSmallSort")
//    public Result addSmallSort(@RequestBody AddSmallSortParam addSmallSortParam){
//
//
//        return null;
//    }
    //删除小类
    @DeleteMapping("/delSmallSort")
    @CrossOrigin("*")
    public Result delSmallSort(List<Integer> intList){
        log.info("删除多个小类接口 参数={}",intList);
        sortServiceImpl.delSmallSort(intList);
        return new Result(true,"2002","删除成功",null);
    }
    //分页带条件查询小类下级
    @PostMapping("/getSmallJunior")
    @CrossOrigin("*")
    public Result getSmallJunior(@RequestBody GetSmallJuniorParam getSmallJuniorParam){
        log.info("分页带条件查询小类下级接口 参数={}",getSmallJuniorParam);
        SortPageDto smallJunior = sortServiceImpl.getSmallJunior(getSmallJuniorParam);
        return new Result(true,"2002","查询集合成功",smallJunior);
    }
    //删除多个小类下级
    @DeleteMapping("/delSmallJunior")
    @CrossOrigin("*")
    public Result delSmallJunior(@RequestParam(value = "intList")List<Integer> intList){
        log.info("删除多个小类下级接口 参数={}",intList);
        sortServiceImpl.delSmallJunior(intList);
        return new Result(true,"2002","删除成功",null);
    }
    //新增小类下级组
    @PostMapping("/addSmallJunior")
    @CrossOrigin("*")
    public Result addSmallJunior(@RequestBody AddJuniorParam juniorParam){
        log.info("新增小类下级组接口 参数={}",juniorParam);
        sortServiceImpl.addSmallJunior(juniorParam);
        return new Result(true,"2002","添加成功",null);
    }
    //增加修改单个小类
    @PostMapping("/smallJunior")
    @CrossOrigin("*")
    public Result smallJunior(@RequestBody AddSmallJuniorParam addSmallJuniorParam) {
        log.info("增加修改单个小类接口 参数={}",addSmallJuniorParam);
        sortServiceImpl.smallJunior(addSmallJuniorParam);
        return new Result(true, "2002", "操作成功", null);
    }
    //商品查询小类
    @GetMapping("/getGoodsSmall")
    @CrossOrigin("*")
    public Result getGoodsSmall(){
        List<GoodsSmallSortDto> goodsSmall = sortServiceImpl.getGoodsSmall();
        return new Result(true, "2002", "查询集合成功", goodsSmall);
    }

}

